#!/usr/local/bin/python3
# -*- coding: UTF-8 -*-
import json
import os
import shutil
import sys
import time
import zipfile
import re
from Common import *
from Core.exportNodesFile import exportNodesFile
from Core.makeNodesFile import *
from Map.test import *
from Script import *

# from Template.CommonTemplate.CommonTemplate import *
# from Template.ThreePalaceTemplate.ThreePalaceTemplate import *


#  ./exe.py /Users/b612/Desktop/kuru开发文档/B6C/python_test/MakeScript.2/zip/306693_7_plain.zip /Users/b612/Desktop/kuru开发文档/B6C/python_test/MakeScript.2/zip/84627_4_plain.zip /Users/b612/Desktop/kuru开发文档/B6C/python_test/MakeScript.2/zip/305407_10_plain.zip
# ./main.py /Users/b612/Desktop/kuru开发文档/B6C/python_test/MakeScript.2/sticker/sticker /Users/b612/Desktop/kuru开发文档/B6C/python_test/MakeScript.2/zip/84627_4_plain.zip /Users/b612/Desktop/kuru开发文档/B6C/python_test/MakeScript.2/zip/84627_4_plain的副本.zip
# ./exe.py  /Users/b612/Desktop/kuru开发文档/B6C/python_test/MakeScript.2/zip/84627_4_plain.zip /Users/b612/Desktop/kuru开发文档/B6C/python_test/MakeScript.2/zip/84627_4_plain的副本.zip /Users/b612/Desktop/kuru开发文档/B6C/python_test/MakeScript.2/zip/84627_4_plain的副本2.zip 
# 
# @ 类型
# @ scriptOutPath
# @ zip路径
# @ 
#       
 
def MakeScript(modulename):
    #解析输入，目前以输入形式，应该以json或者其他形式
    # outpath  zippath[,,,,]     
    if sys.argv[1]=="d":
        shutil.rmtree("/Users/b612/Desktop/kuru开发文档/B6C/python_test/MakeScript.2/Sticker/Sticker/")
        os.makedirs("/Users/b612/Desktop/kuru开发文档/B6C/python_test/MakeScript.2/Sticker/Sticker") 
        shutil.rmtree("/Users/b612/Desktop/kuru开发文档/B6C/python_test/MakeScript.2/zip/306693_7_plain/")
        shutil.rmtree("/Users/b612/Desktop/kuru开发文档/B6C/python_test/MakeScript.2/zip/84627_4_plain/")
        shutil.rmtree("/Users/b612/Desktop/kuru开发文档/B6C/python_test/MakeScript.2/zip/305407_10_plain/")
        exit(0)


    zipPath=[0 for i in range(1, len(sys.argv))]    
    for i in range(1, len(sys.argv)):
        # print("参数", i, sys.argv[i])
        zipPath[i-1]=sys.argv[i]
    
    
#     createMap()  
    modulePath="Template."+str(modulename)+"."+str(modulename)
    try:
        module=__import__(modulePath)
    except ModuleNotFoundError:
        print("没有该模块")
        exit(0)
    else:
        productName="product1"
        module=__import__(modulePath)
    
        firstModule=getattr(module, modulename)

        secondModule=getattr(firstModule, modulename)
   
        templateName=getattr(secondModule, modulename)
        if hasattr(templateName, '__init__'):
            template=templateName(zipPath)
            template.CreateIndexAndMetadataJson()
            template.CopySpecificResource()
            # 创建node拷贝资源    
            template.createAndCopyNodesResource(zipPath,productName)
            print(template.getOutPutPath)
        else:
            print("没有该类")
            exit(0)

if __name__ == "__main__":
    MakeScript("ThreePalaceTemplate")

